package com.ls.thread.produce_consumer;

public class Stroe {
	
	private int pro;
	
	
	public synchronized void addpro(){
		
		if(pro>=20){
			
			try {
				notify();
				System.out.println("达到最大产品容量，生产者先休息");
				System.out.println();
				wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}else{
			
			pro=pro+1;
			System.out.println(Thread.currentThread().getName()+"："+"生产了第"+pro+"个产品");
			
			
			notifyAll();
		}
		
	}
	
	public synchronized void subpro(){
		
		if(pro<0){
			try {
				notify();
				System.err.println("没有产品了，消费者先休息下");
				System.out.println();
				wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}else{
			pro=pro-1;
			System.err.println(Thread.currentThread().getName()+":"+"消费了第"+pro+"个产品");
			notifyAll();
		}
	}

}
